package cn.iocoder.yudao.module.alipay.service.linalian;

import cn.iocoder.yudao.module.alipay.controller.app.lianlian.vo.LianLianOrderCreateReqVO;
import cn.iocoder.yudao.module.alipay.service.common.LianLianProperties;
import cn.iocoder.yudao.module.alipay.util.AesUtils;
import cn.iocoder.yudao.module.alipay.util.HttpUtils;
import cn.iocoder.yudao.module.alipay.util.Md5Util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LLOrderServiceImpl  implements  LLOrderService{

    @Resource
    private LianLianProperties lianLianProperties;

    @Override
    public Object createOrder(LianLianOrderCreateReqVO createReqVO) throws Exception {
        String url = lianLianProperties.getDebugHttpUrl()+"/channel/order/create";
        Object json = JSONObject.toJSON(createReqVO);
        String createReqVOData = JSON.toJSONString(json);
        String encryptedData = AesUtils.aesEncrypt(createReqVOData, "ri17cWAp0rvozL9Cb94xtQ==");
        Long timestamp = System.currentTimeMillis();
        String sign = Md5Util.encrypt(encryptedData + lianLianProperties.getChannelId() + timestamp.toString());
        JSONObject paramData = new JSONObject();
        paramData.put("sign",sign);
        paramData.put("timestamp",timestamp);
        paramData.put("encryptedData",encryptedData);
        paramData.put("channelId",lianLianProperties.getChannelId());
        String result = HttpUtils.sendPost(paramData,url);

        //String decryptedData = AesUtils.aesEncrypt(encryptedData, AES秘钥);
        return result;
    }

}
